#ifndef QBCISOURCE_H
#define QBCISOURCE_H

#include "qbciglobal.h"
#include "qbcimod.h"

#include <QSharedPointer>

namespace bci {
class QBciSource : public QBciMod {
  Q_OBJECT

  friend class BciApplication;

public:
  explicit QBciSource(const QString &id);
  virtual ~QBciSource(){};

  enum RunType { Loop, Slot };

protected slots:
  /*!
   * \brief start函数会在 BciApplication 发出开始信号后执行
   *
   * \note 子类如果是Loop模式则会不断运行run直到BciApplication发出停止信号,
   * run函数本身就会在线程内不断调用，不能用死循环将其阻塞，否则会把线程卡住
   * 如果是Slot模式，应该由另一个异步信号调用run()
   */
  virtual void run() = 0;

public:
  /**
   * @brief Set the Run Type object
   *
   * Loop: run() will be executed over and over again
   * Slot: run() will be only executed by signal
   */
  void setRunType(const RunType type) {
    if (isRunning()) {
      error("Cannot change runType while module running.");
      return;
    }
    runType = type;
  }

signals:
  void sendData(QSharedPointer<::bci::QBciSignal> signal);

protected slots:
  void afterStart() override;

private slots:
  void privateRun();

protected:
  RunType runType = Slot;
};
} // namespace bci

#endif